/* Array 函数处理部分
 * 如果引入jquery/underscore，许多函数会有现成的
 *
 *
 *
 */

Array.prototype.insert = function(index, item) {
    this.splice(index, 0, item)
}

Array.prototype.remove = function(index, num) {
    this.splice(index, num)
}

// 从index1处开始num1个数字与调动到index2处
Array.prototype.move = function(index1, num1, index2) {
    if (num1 < 0) {
        throw new Error("error input");
    }
    if (index1 + num1 > this.length) {
        throw new Error("range beyond array length");
    }
    if (index2 > this.length) {
        throw new Error("range beyond array length");
    }

    var items = this.splice(index1, num1);

    for (var i = 0; i < items.length; i++) {
        var ele = items[i];
        this.splice(index2, 0, ele)
        index2 += 1;
    }
}

